home *** CD-ROM | disk | FTP | other *** search
- /* $VER: InsertIt V1.03 (25.10.96) Shaun Downend.
- * <shaund@amiganut.demon.co.uk>
- * Insert useful information into a message.
- *
- * Supported editors:-
- * FSE (Thor internal editor), GoldED, TurboText, and CygnusED.
- * Clipboard support for other editors.
- *
- * This script should be launched from your text editor!
- */
-
- /****************************************************/
- /* Edit the configuration below to suit your system */
- /****************************************************/
-
- htmlhotlist = 'AWeb:AWeb.hotlist' /* path and filename of browser hotlist */
-
- hotlistmode = 'A' /* H = HTML hotlist (IBrowse, Voyager) *
- * A = AWeb hotlist (v1.2b, v1.4, v2.0) */
-
- mode = 'A' /* Mode of operation (I/C/A) *
- * I = Insert into message *
- * C = Save to Clipboard ONLY *
- * A = Ask user */
-
- cutmarkers = 1 /* Option to insert "cut here" markers. 1 = enable, 0 = disable
- * The marker begin and end strings are set below.
- */
-
- cutstart = '----8<----'
- cutend = '---->8----'
-
- /****************************************************/
- /* end of configuration - do not edit below here */
- /****************************************************/
-
- options results
-
- scriptver = subword(sourceline(1), 4,1)
-
- /*!~ "check for arexx ports" */
-
- editorport = ''
-
- /* List of supported editors and arexx commands to insert text - expandable */
-
- rp.count = 4
-
- rp.name.1 = 'GOLDED'
- rp.text.1 = 'CLIP PASTE'
- rp.name.2 = 'THOR_FSE'
- rp.text.2 = 'PASTECLIP'
- rp.name.3 = 'rexx_ced'
- rp.text.3 = 'PASTE'
- rp.name.4 = 'TURBOTEXT'
- rp.text.4 = 'PASTECLIP'
-
- /* Check for existance of an editor */
-
- do i = 1 to rp.count
- if(substr(address(),1,length(rp.name.i)) = rp.name.i) then
- do
- editorport = address()
- addtext = rp.text.i
- end
- end
-
- if editorport = '' & (upper(mode) = 'I' | upper(mode) = 'A') then
- do
- say 'This script has to be run from your editor.'
- say 'GoldED, FSE (Thor''s internal editor), TurboText, and CygnusED are currently supported.'
- say 'To use this script with another editor set MODE = ''C'' in the script to save to clipboard.'
- say 'You will then have to select paste from clipboard manually.'
- exit
- end
-
- /* Check for existance of Thor */
-
- p=' '||address()||' '||show('P',,)
- if pos(' THOR.',p)>0 then
- thorport=word(substr(p,pos(' THOR.',p)+1),1)
- else
- do
- say ('Thor has to be running to use this script!')
- exit(10)
- end
- /*~!*/
- /*!~ "main code" */
-
- address(thorport)
-
- call insertchoice /* insert url, fileinfo, message info, or file info? */
-
- parse var result action searchfor
-
- searchfor = upper(strip(searchfor))
- if searchfor = '' then exit(5)
-
- if action = 1 then /* process hotlist */
- do
- if ~exists(htmlhotlist) then
- do
- call errmsg(htmlhotlist' does not exist.\nPlease configure htmlhotlist to match a hotlist on your hd.',0)
- exit(10)
- end
- else
- do
- call searchhotlist
- if LIST.COUNT = 0 then call errmsg('No matching URL''s found.',0)
- call selmatches
- call restorehl
- end
- end
-
- if action = 2 then /* process filedatabase */
- do
- if ~show('p', 'BBSREAD') then
- do
- address command
- "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
- "WaitForPort BBSREAD"
- end
- call selbbs
- call filesearch
- if LIST.COUNT = 0 then call errmsg('No matching files found.',0)
- call selmatches
- end
-
- if action = 3 then /* process message */
- do
- call savemsg
- call scanfile(tempfile)
- if LIST.COUNT = 0 then call errmsg('Insert message aborted.',0)
- if LIST.COUNT ~= 0 then address command 'c:delete >NIL: 'tempfile
- call selmatches
- end
-
- if action = 4 then /* process file */
- do
- call selfile
- call scanfile(tempfile)
- if LIST.COUNT = 0 then call errmsg('Insert file aborted.',0)
- call selmatches
- end
-
- call insert /* insert/clip text */
-
- exit(0)
- /*~!*/
- /*!~ "Insert what?" */
- insertchoice: procedure
-
- 'requestnotify text "InsertIt options..." bt "_URL|_FileInfo|_Message|File|_Cancel"'
- if result = 0 then exit(0)
- if result = 1 then /* select url to search for */
- do
- call searchstring('InsertURL','Insert search string...\n\nIt can be a keyword in the URL or in \nthe name of the web page.')
- parse var result searchfor
- return 1 searchfor
- end
- if result = 2 then /* select file to search for */
- do
- call searchstring('InsertFileInfo','Insert search string...\n\nIt can be a keyword from an Aminet file.')
- parse var result searchfor
- return 2 searchfor
- end
- if result = 3 then return 3 'nosearch' /* no search - message selected */
- if result = 4 then return 4 'nosearch' /* no search - file selected */
- return
- /*~!*/
- /*!~ "Allow user to enter search string" */
- searchstring: procedure
-
- parse arg rstitle,rsbt
-
- 'requeststring title "'rstitle'" bt "_Search|_Cancel" body "'rsbt'"'
- if(rc = 5) then exit
- else if(rc ~= 0)then call errmsg(THOR.LASTERROR,10)
- return result
- /*~!*/
- /*!~ "Search the hotlist for user defined string" */
-
- searchhotlist:
-
- drop SLIST.
- drop LIST.
- m = 0
-
- if(~OPEN(hl,htmlhotlist,'R')) then call errmsg('Unable to open hotlist!',10)
- filelength = SEEK(hl,0,'E')
- call oprog('Scanning hotlist for 'searchfor,filelength,'Looking for...'searchfor'...',abort)
- call seek(hl, 0,'B')
-
- do until currpos = filelength
- prevline = line
- line = readln(hl)
- currpos = seek(hl, 0)
- if (currpos // 10 = 0) then call uprog(window,currpos,'Found 'm' match(es)')
- if result = 5 then call errmsg('InsertIt URL search aborted.',0)
-
- if pos(searchfor,upper(line)) ~= 0 then
-
- do
-
- if upper(hotlistmode) = 'H' then /* html hotlist search */
- do
- m = m + 1
- parse var line '<LI><A HREF="' url '"' ibf '>' name '</A>'
- SLIST.m = strip(name)' :- 'strip(url)
- LIST.m = left(strip(name),20,' ')' :- 'strip(url) /* truncate page name for listview */
- if strip(LIST.m) = ':-' then m = m - 1
- end
-
- if upper(hotlistmode) = 'A' then /* AWeb hotlist search */
- do
- parse var line url
- if pos('TP://',upper(url)) > 0 then
- do /* search string found in URL */
- m = m + 1
- line = readln(hl)
- currpos = seek(hl, 0)
- call uprog(window,currpos,'Found 'm' match(es)')
- if result = 5 then call errmsg('InsertIt URL search aborted.',0)
- parse var line name
- SLIST.m = strip(name)' :- 'strip(url)
- LIST.m = left(strip(name),20,' ')' :- 'strip(url) /* truncate page name for listview */
- if strip(LIST.m) = ':-' then m = m - 1
- end
- else
- do /* search string found in page name */
- name = url
- line = prevline
- parse var line url
- if pos('TP://',upper(url)) > 0 then
- do
- m = m + 1
- call uprog(window,currpos,'Found 'm' match(es)')
- if result = 5 then call errmsg('InsertIt URL search aborted.',0)
- SLIST.m = strip(name)' :- 'strip(url)
- LIST.m = left(strip(name),20,' ')' :- 'strip(url) /* truncate page name for listview */
- if strip(LIST.m) = ':-' then m = m - 1
- end
- end
- end
- end
- end
- call cprog(window)
- LIST.COUNT = m
- SLIST.COUNT = LIST.COUNT
- return
- /*~!*/
- /*!~ "Restore hotlist" */
- restorehl:
-
- do i = 1 to SELECTED.COUNT
- parse var SELECTED.i sname ' :- ' surl
- do h = 1 to SLIST.COUNT
- parse var SLIST.h lname ' :- ' lurl
- if surl = lurl then SELECTED.i = SLIST.h /* restore full page name to insert in editor or clipboard */
- end
- end
- return
- /*~!*/
- /*!~ "Search for files in database" */
-
- filesearch:
-
- drop LIST.
-
- c = 0
-
- call oprog('Searching for 'searchfor,1,'Scanning filedatabase...')
- address (bbsread)
- 'searchbrfile bbsname "'bbs'" stem' SRESULT 'search "'searchfor'" keyword'
-
- if(result > 0) then
- do /* matches have been found in the filedatabase */
- call uprog(window,1,'Completed')
- if result = 5 then call errmsg('InsertIt File info search aborted.',0)
- do w = 1 to 400 /* delay */
- end
- call cprog(window)
- call oprog('Searching for 'searchfor,1,'Searching file areas...',abort)
- call uprog(window,0,'Searching 'SRESULT.FILEAREA.f' ('f'/'SRESULT.FILEAREA.COUNT') Found 'c' file(s).',SRESULT.FILEAREA.COUNT)
- if result = 5 then call errmsg('InsertIt File info search aborted.',0)
- do f=1 to SRESULT.FILEAREA.COUNT /* process fileareas */
- do i=1 to SRESULT.FILE.f.COUNT /* process files in each filearea */
- address(bbsread)
- call showfiledata('"'bbs'"', '"'SRESULT.FILEAREA.f'"', SRESULT.FILE.f.i) /* get file info */
- call uprog(window,f,'Searching 'SRESULT.FILEAREA.f' ('f'/'SRESULT.FILEAREA.COUNT') Found 'c' file(s).')
- if result = 5 then call errmsg('InsertIt File Info search aborted.',0)
- end
- end
- LIST.COUNT = c
- call cprog(window)
- end
- else
- do
- LIST.COUNT = 0 /* no matching files have been found */
- call uprog(window,1,'Completed')
- if result = 5 then call errmsg('InsertIt File Info search aborted.',0)
- do w = 1 to 400 /* delay */
- end
- call cprog(window)
- end
- return
-
- /*!~ Procedure to show the data about a file */
-
- showfiledata: procedure expose LIST. c
-
- parse arg bbs,farea,filenr
-
- FDF_DELETED = '00000001'x
-
- drop FILE.
-
- address (bbsread)
- 'readbrfile' bbs farea filenr 'tagsstem' FILE 'datastem' DATA
-
- nextfile = result
-
- if (bitand(DATA.FLAGS,FDF_DELETED) ~= FDF_DELETED) then /* file is not deleted */
- do
- if(symbol("FILE.SIZE") = "VAR") then fsize = FILE.SIZE
- else size = "Unkn"
-
- if(symbol("FILE.DESCRIPTION.COUNT") = "VAR") then descr = FILE.DESCRIPTION.1
- else descr = "NONE"
-
- c = c + 1
- /* format file information in Aminet RECENT format */
- LIST.c = left(FILE.NAME,18) || ' ' || left(strip(farea,B,'"'),10,' ') || ' ' || right(fsize,7) || ' ' || left(descr,39)
- end
- else
- do
- c = c + 1
- LIST.c 'File is deleted.'
- end
-
- return
- /*~!*/
-
- /*~!*/
- /*!~ "Save message and prepare for listview" */
- savemsg:
-
- tempfile = 't:InsertIt.'time(s)
-
- 'savemessage current overwrite noheader noansi filename' tempfile /* save current msg in main window */
- if rc = 5 then call errmsg('Message is deleted',0)
- if rc ~= 0 then call errmsg('SAVEMESSAGE failed: 'THOR.LASTERROR,10)
-
- return
- /*~!*/
- /*!~ "Select file" */
- selfile:
-
- 'requestfile title "Select a file:" id "ram:" fp pat "#?"'
- if(rc=5) then call errmsg('Aborted file search',0)
- if(rc~=0) then call errormsg('REQUESTFILE failed: 'THOR.LASTERROR,10)
-
- tempfile = result
-
- return
- /*~!*/
- /*!~ "Scan file" */
- scanfile:
-
- parse arg tempfile
-
- drop LIST.
- m = 0
- if(~open(msg,tempfile,'R')) then call errmsg('Unable to open tempfile!',10)
- filelength = SEEK(msg,0,'E')
- m = m + 1
- call oprog('Scanning file...',filelength,'Processing line 'm'...',abort)
- call seek(msg, 0,'B')
-
- do until currpos = filelength /* read file into stem for listview */
- line = readln(msg)
- currpos = seek(msg, 0)
- LIST.m = line
- if (m // 10 = 0) then call uprog(window,currpos,'Processing line 'm'...')
- if result = 5 then call errmsg('InsertIt message/file search aborted.',0)
- m = m + 1
- end
- call cprog(window)
- call close(msg)
- LIST.COUNT = m
-
- return
- /*~!*/
- /*!~ "Display matched entries" */
-
- selmatches:
- drop SELECTED.
- SELECTED.COUNT = 0
- address(thorport)
- 'requestlist instem' LIST 'outstem' SELECTED 'title "Select entries to insert into message:" dragselect'
- if(rc = 5) then exit(0)
- if(rc ~= 0) then call errmsg(THOR.LASTERROR,10)
- return
- /*~!*/
- /*!~ "Insert selected entries into editor" */
-
- insert:
- lf = '0a'x
-
- if upper(mode) = 'A' then
- do
- address(thorport)
- 'requestnotify text "InsertIt options..." bt "_Insert|_Save to Clipboard only|_Cancel"'
- if result = 0 then exit(0)
- if result = 1 then mode = 'I'
- if result = 2 then mode = 'C'
- end
-
- cliptext = ''
- cliptemp = 't:cliptemp'
- if(~open(ctemp,cliptemp,'W')) then call errmsg('Unable to open clipfile!',10)
- if cutmarkers = 1 then call writeln(ctemp,cutstart)
- do i = 1 to SELECTED.COUNT
- call writeln(ctemp,SELECTED.i) /* write info to file to put into clipboard */
- end
- if cutmarkers = 1 then call writeln(ctemp,cutend)
- call close(ctemp)
- address(thorport)
- 'putclip file' cliptemp
- if(rc ~= 0) then call errmsg(THOR.LASTERROR,10)
- address command 'c:delete >NIL: 'cliptemp
- if(rc~=0) then call errmsg('Unable to delete cliptemp!',10)
-
-
- if upper(mode) = 'I' then
- do
- if editorport ~= '' then
- do
- address(editorport)
- addtext
- end
- end
-
- return
- /*~!*/
- /*!~ "Display error message and exit" */
-
- errmsg:
- parse arg msgtxt,failcode
- address(thorport)
- 'requestnotify "'msgtxt'"' '" _OK "'
- if(rc = 30) then say THOR.LASTERROR
- exit(failcode)
- return
- /*~!*/
- /*!~ "Select BBS" */
-
- selbbs:
- address (bbsread)
- 'getbbslist stem' BBSLIST
- if(rc ~= 0) then call errmsg(BBSREAD.LASTERROR,10)
- if BBSLIST.count = 1 then
- do
- bbs = BBSLIST.1
- return
- end
- address(thorport)
- 'thortofront'
-
- 'requestlist instem' BBSLIST 'title "Select BBS:" SIZEGADGET'
- if(rc ~= 0) then exit
- else bbs = result
- return
- /*~!*/
- /*!~ "Open progress indicator" */
- oprog:
- parse arg ptitle,ptotal,ptxt,at
- if at ~= '' then at = 'at "_Abort"'
- address(thorport)
- 'openprogress title "'ptitle'" total' ptotal 'pt "'ptxt'"' at
- if(rc ~= 0) then call errmsg('OPENPROGRESS failed: 'THOR.LASTERROR,10)
- else window = result
- return
- /*~!*/
- /*!~ "Update progress indicator" */
- uprog:
- parse arg pwindow,pcurrent,ptxt,ptotal
- if ptotal = '' then ptotal = ''
- else ptotal = 'total 'ptotal
- address(thorport)
- 'updateprogress req' pwindow 'current' pcurrent ptotal 'pt "'ptxt'"'
- if(rc=5) then
- do
- call cprog(pwindow)
- return(5)
- end
- if(rc=30) then call errmsg('UPDATEPROGRESS failed: 'THOR.LASTERROR,10)
- return(0)
- /*~!*/
- /*!~ "Close Progress indicator" */
- cprog:
- parse arg pwindow
- address(thorport)
- 'closeprogress req' pwindow
- return
- /*~!*/
-
-